// Copyright 2011 Google Inc. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package dfa.axis.v1_16;

import com.google.api.ads.dfa.lib.client.DfaSession;
import com.google.api.ads.dfa.lib.factory.DfaServices;
import com.google.api.ads.dfa.axis.v1_16.SpotlightActivity;
import com.google.api.ads.dfa.axis.v1_16.SpotlightActivitySaveResult;
import com.google.api.ads.dfa.axis.v1_16.SpotlightRemote;

import java.net.URL;

/**
 * This example creates a spotlight activity in a given activity group. To
 * create an activity group, run CreateSpotlightActivityGroup.java. To get tag
 * methods types, run GetTagMethodTypes.java. To get activity type IDs, run
 * GetActivityTypes.java.
 *
 * Credentials and properties in {@code fromFile()} are pulled from the
 * "ads.properties" file. See README for more info.
 *
 * Tags: spotlight.saveSpotlightActivity
 *
 * @author Joseph DiLallo
 */
public class CreateSpotlightActivity {

  public static void main(String[] args) throws Exception {
    long activityGroupId = Long.parseLong("INSERT_ACTIVITY_GROUP_ID_HERE");
    long activityTypeId = Long.parseLong("INSERT_ACTIVITY_TYPE_ID_HERE");
    long tagMethodTypeId = Long.parseLong("INSERT_TAG_METHOD_TYPE_ID_HERE");
    String url = "INSERT_EXPECTED_URL_HERE";
    String activityName = "INSERT_ACTIVITY_NAME_HERE";

    // Initialize your session.
    DfaSession session = new DfaSession.Builder().fromFile().build();

    // Request the service.
    SpotlightRemote service = new DfaServices().get(session, SpotlightRemote.class);

    // Set spotlight activity structure.
    SpotlightActivity spotActivity = new SpotlightActivity();
    spotActivity.setId(0);
    spotActivity.setName(activityName);
    spotActivity.setActivityGroupId(activityGroupId);
    spotActivity.setActivityTypeId(activityTypeId);
    spotActivity.setTagMethodTypeId(tagMethodTypeId);
    spotActivity.setExpectedUrl(new URL(url).toString());

    // Create the spotlight tag activity.
    SpotlightActivitySaveResult spotlightActivityResult =
        service.saveSpotlightActivity(spotActivity);

    // Display new spotlight activity ID.
    if (spotlightActivityResult != null) {
      System.out.print("Spotlight activity with ID \"" + spotlightActivityResult.getId()
          + "\" was created.");
    }
  }
}
